package org.example.translate_braille.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.example.translate_braille.entity.User;
import org.example.translate_braille.entity.login.LoginDto;
import org.example.translate_braille.entity.login.LoginVo;
import org.example.translate_braille.resdata.X;
import org.example.translate_braille.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Jacky
 */
@RestController
@RequestMapping("/translate_braille")
@Api(tags = "登录")
public class LoginController {

    @Autowired
    LoginService loginService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public X<LoginVo> appLogin(@RequestBody JSONObject jsonObject){
        System.out.println(jsonObject.toString());
        LoginDto loginDto = new LoginDto();
        loginDto.setCode(jsonObject.getString("code"));
        loginDto.setImg(jsonObject.getString("img"));
        loginDto.setNickName(jsonObject.getString("nickname"));

        System.out.println(loginDto);
        return  loginService.login(loginDto);
    }

    @PostMapping("/weblogin")
    @ApiOperation("网页登录")
    public X<LoginVo> webLogin(@RequestBody JSONObject jsonObject){
        System.out.println(jsonObject.toString());
        User user = new User();
        user.setUserName(jsonObject.getString("username"));
        user.setUserPassword(jsonObject.getString("password"));
        return  loginService.webLogin(user);
    }

    @PostMapping("/webRegister")
    @ApiOperation("网页登录")
    public X<LoginVo> webRegister(@RequestBody JSONObject jsonObject){
        System.out.println(jsonObject.toString());
        User user = new User();
        user.setUserName(jsonObject.getString("username"));
        user.setUserPassword(jsonObject.getString("password"));
        user.setOpenId("网页用户无OpenID");
        user.setUserImg("网页用户无头像");
        return  loginService.webRegister(user);
    }

    @GetMapping("/logout")
    @ApiOperation("登出")
    public String appLogout(){
        return "666666";
    }
}
